function HandleLoginBtnClick() {
    const user = document.getElementById("user");
    const password = document.getElementById("password");
    
    if(user.value && password.value) {
        const loginBtn = document.getElementById("login");
        loginBtn.textContent = "Logging in...";

        const loginData = {
            username: user.value,
            password: password.value
        };
        const jsonData = JSON.stringify(loginData);
        console.log(jsonData);
        SendHttpRequest(jsonData);
    } else {
        alert("Please input correct user account or password!");
    }
}

function SendHttpRequest(jsonData) {
    const url = 'http://111.229.129.235:80';
    const request = new XMLHttpRequest();
    request.open('POST', url, true);
    request.setRequestHeader('Content-Type', 'application/json');
    request.onreadystatechange = function() {
        if (request.readyState == XMLHttpRequest.DONE) {
            if(request.status == 200) {
                console.log(request.responseText);
                const response = JSON.parse(request.responseText);
                console.log("Request success");
                console.log(response);
                console.log(res);
            } else {
                console.error('Request failed:', request.status, request.statusText);
            }
        }
    };
    var res = request.send(jsonData);
}